﻿app.controller("previewCtrl",
	function($scope, $http, $location) {
	    var pos = 0;
        var lastX = 0;
        var isMouseDown = false;
        var pageSize = 600;

        $scope.imagesPrefix = "http://qishonpic.oss-cn-shanghai.aliyuncs.com/web3dpic/";
		function previewShow() {
			 $http.get("/previewJson?partCode="+$location.search().partCode+"&imageType="+$location.search().imageType)
			        .success(function (data) {

			        	$scope.masPartHd = eval(data);
			        	if(data.masPartRegions.length!=0)
			        	{
			        	    document.getElementById("operationWindow").style.width = eval(data).imageSize+"px";
			        	    document.getElementById("operationWindow").style.height = eval(data).imageSize+"px";
			        	    pageSize = eval(data).imageSize;
			        	}
			        	else
			        	{
			        	    $scope.masPartHd = null;
			        	}
			        })
			        .error(function (data){
			        	$scope.masPartHd = null;
			        });
		}
        $scope.regionSelect = function regionSelect(obj) {
            $(".region-page").hide();
            $("#region_" + obj.masPartRegion.regionCode).show();
        }

        $scope.fabricSelect = function fabricSelect(obj) {
            $("#images_" + obj.masPartRegion.regionCode)[0].src = $scope.imagesPrefix + obj.masPartFabric.fullFilePath;
        }

        previewShow();
        $("#friends").mousedown(function(e) {
                lastX = e.pageX;
                isMouseDown = true;
            });

            $("#friends").mouseup(function(e) {
                isMouseDown = false;
            });

            $("#friends").mousemove(function(e) {
                if (isMouseDown) {
                    var diff = parseInt((e.pageX - lastX) / pageSize * 24 * 2);
                    if (diff != 0) {
                        lastX = e.pageX;
                        turns(diff);
                    }
                }
            });

            function turns(dirs) {
                var sContainer = $(".showContainer");
                var turns_maxi = sContainer.length;
                pos = (pos + dirs) % 24;
                if (pos < 0) {
                    pos = pos + 24;
                }
                var xLeft = -pos * pageSize + "px";
                for (var i = 0; i < turns_maxi; i++) {
                    sContainer[i].style.left = xLeft;
                }

            }
	});


jQuery(function($) {
    /*var pos = 0;
    var lastX = 0;
    var isMouseDown = false;

    $("#friends").mousedown(function(e) {
        lastX = e.pageX;
        isMouseDown = true;
    });

    $("#friends").mouseup(function(e) {
        isMouseDown = false;
    });

    $("#friends").mousemove(function(e) {
        if (isMouseDown) {
            var diff = parseInt((e.pageX - lastX) / 600 * 24 * 2);
            if (diff != 0) {
                lastX = e.pageX;
                turns(diff);
            }
        }
    });

    function turns(dirs) {
        var sContainer = $(".showContainer");
        var turns_maxi = sContainer.length;
        pos = (pos + dirs) % 24;
        if (pos < 0) {
            pos = pos + 24;
        }
        var xLeft = -pos * 600 + "px";
        for (var i = 0; i < turns_maxi; i++) {
            sContainer[i].style.left = xLeft;
        }

    }
    */

    //屏蔽鼠标右键菜单
    document.oncontextmenu = function(e){
    	e.preventDefault();
    };

});